package com.songhuan.web.controller;

import com.songhuan.web.SysConst;
import com.songhuan.web.dto.UploadFaceInput;
import com.songhuan.web.tools.FaceUtils;
import com.songhuan.web.tools.dto.ResponseData;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * 人脸接口
 */
@RestController()
@RequestMapping("/Face")
public class FaceController {
    /**
     * 上传人脸
     */
    @RequestMapping(value = "/UploadFace", method = RequestMethod.POST)
    @SneakyThrows
    public ResponseData<String> UploadFace(@RequestBody UploadFaceInput input) {

        String facetoken = FaceUtils.FaceAdd(input.getImage(), SysConst.SYSTEM_CODE, input.getUserId());
        return ResponseData.GetResponseDataInstance(facetoken, "识别成功", true);
    }

    /**
     * 人脸搜索
     */
    @RequestMapping(value = "/FaceSearch", method = RequestMethod.POST)
    @SneakyThrows
    public ResponseData<String> FaceSearch(@RequestBody UploadFaceInput input) {

        String jsonObject = FaceUtils.FaceSearch(input.getImage(), SysConst.SYSTEM_CODE);
        return ResponseData.GetResponseDataInstance(jsonObject, "识别成功", true);
    }
    /**
     * 用户人脸
     */
    @RequestMapping(value = "/UserFace", method = RequestMethod.POST)
    @SneakyThrows
    public ResponseData<ArrayList<String>> UserFace(@RequestBody UploadFaceInput input) {

        ArrayList<String> faceTokens = FaceUtils.UserFace(input.getUserId(), SysConst.SYSTEM_CODE);
        return ResponseData.GetResponseDataInstance(faceTokens, "查询成功", true);
    }

    /**
     * 用户人脸删除
     */
    @RequestMapping(value = "/UserFaceDel", method = RequestMethod.POST)
    @SneakyThrows
    public ResponseData<String> UserFaceDel(@RequestBody UploadFaceInput input) {

        String res = FaceUtils.UserFaceDel(input.getUserId(), SysConst.SYSTEM_CODE);
        return ResponseData.GetResponseDataInstance(res, "删除成功", true);
    }


    /**
     * 用户单个人脸删除
     */
    @RequestMapping(value = "/UserFaceTokenDel", method = RequestMethod.POST)
    @SneakyThrows
    public ResponseData<String> UserFaceTokenDel(@RequestBody UploadFaceInput input) {

        String res = FaceUtils.UserFaceTokenDel(input.getUserId(), SysConst.SYSTEM_CODE,input.getFaceToken());
        return ResponseData.GetResponseDataInstance(res, "删除成功", true);
    }

}
